// pages/image/image.js
Page({
  data: {
    documents: [{
        name: '操作技能考核内容层次结构表',
        url: 'https://web-dai-yaya.oss-cn-beijing.aliyuncs.com/e929f851-b4b6-460f-8e48-abea201b9a11.docx'
      },
      {
        name: '初级工操作技能试题',
        url: 'https://web-dai-yaya.oss-cn-beijing.aliyuncs.com/0c7af4f7-a2e6-42ab-9f9b-c811353b764d.docx'
      },
      {
        name: '天然气压缩机工技师鉴定要素细目表',
        url: 'https://web-dai-yaya.oss-cn-beijing.aliyuncs.com/161a6589-a0a7-4ac6-abd9-ad1839e083e7.docx'
      },
      {
        name: '中级操作技能考试内容层次结构表',
        url: 'https://web-dai-yaya.oss-cn-beijing.aliyuncs.com/76f5e083-f7b9-451d-9e67-63d36aafdbce.docx'
      },
      {
        name: '天然气压缩机工高级技师鉴定要素细目表',
        url: 'https://web-dai-yaya.oss-cn-beijing.aliyuncs.com/a7acc570-72e1-47d2-a69e-767431664dae.docx'
      },
      {
        name: '压缩机常见故障判断与排除',
        url: 'https://web-dai-yaya.oss-cn-beijing.aliyuncs.com/2019757d-dde4-4791-9176-d6e90e6728c8.pptx'
      }
    ]
  },

  downloadDocument: function (event) {
    const url = event.currentTarget.dataset.url; // 获取文档链接
    const that = this;

    wx.downloadFile({
      url: url,
      success: function (res) {
        // 检查下载是否成功
        if (res.statusCode === 200) {
          // 使用 wx.openDocument 打开下载的文档
          wx.openDocument({
            filePath: res.tempFilePath,
            success: function (res) {
              console.log('文档打开成功');
            },
            fail: function (error) {
              console.error('文档打开失败:', error);
            }
          });
        } else {
          wx.showToast({
            title: '下载失败',
            icon: 'none'
          });
        }
      },
      fail: function (error) {
        console.error('文件下载失败:', error);
        wx.showToast({
          title: '下载失败',
          icon: 'none'
        });
      }
    });
  },
  btnClick() {
    wx.setClipboardData({
      data: 'https://web-dai-yaya.oss-cn-beijing.aliyuncs.com/往复式压缩机总课件.pptx',
      success(res) {
        wx.showToast({
          title: '复制成功',
        });
      },
      fail(err) {
        wx.showToast({
          title: '复制失败',
          icon: 'none',
        });
      },
    });
  }
});